<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="utf-8">
    <title>{% block title %}高中数学助手{% endblock %}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <style>
        :root {
            color-scheme: light;
            font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
            
            /* 主色调 - 使用更现代的蓝紫色系 */
            --primary-50: #f0f4ff;
            --primary-100: #e0e7ff;
            --primary-200: #c7d2fe;
            --primary-300: #a5b4fc;
            --primary-400: #818cf8;
            --primary-500: #6366f1;
            --primary-600: #4f46e5;
            --primary-700: #4338ca;
            --primary-800: #3730a3;
            --primary-900: #312e81;
            
            /* 中性色 */
            --gray-50: #f9fafb;
            --gray-100: #f3f4f6;
            --gray-200: #e5e7eb;
            --gray-300: #d1d5db;
            --gray-400: #9ca3af;
            --gray-500: #6b7280;
            --gray-600: #4b5563;
            --gray-700: #374151;
            --gray-800: #1f2937;
            --gray-900: #111827;
            
            /* 语义化颜色 */
            --success-50: #f0fdf4;
            --success-500: #22c55e;
            --success-600: #16a34a;
            --success-700: #15803d;
            
            --warning-50: #fef3c7;
            --warning-500: #eab308;
            --warning-600: #ca8a04;
            
            --danger-50: #fef2f2;
            --danger-500: #ef4444;
            --danger-600: #dc2626;
            --danger-700: #b91c1c;
            
            /* 应用色值 */
            --surface: var(--gray-50);
            --surface-elevated: #ffffff;
            --text-primary: var(--gray-900);
            --text-secondary: var(--gray-600);
            --text-tertiary: var(--gray-500);
            --border-subtle: var(--gray-200);
            --border-medium: var(--gray-300);
            
            --accent: var(--primary-600);
            --accent-hover: var(--primary-700);
            --accent-soft: var(--primary-50);
            --accent-light: var(--primary-100);
            
            --success: var(--success-600);
            --success-light: var(--success-50);
            --warning: var(--warning-600);
            --warning-light: var(--warning-50);
            --danger: var(--danger-600);
            --danger-light: var(--danger-50);
            
            --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
            --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
            --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
            --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
            
            --radius-sm: 8px;
            --radius-md: 12px;
            --radius-lg: 16px;
            --radius-xl: 20px;
            --radius-full: 9999px;
            
            --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
            --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
            --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
        }

        body[data-theme="dark"] {
            --surface: #0f172a;
            --surface-elevated: #1e293b;
            --text-primary: #f1f5f9;
            --text-secondary: #cbd5e1;
            --text-tertiary: #94a3b8;
            --border-subtle: rgba(148, 163, 184, 0.1);
            --border-medium: rgba(148, 163, 184, 0.2);
            
            --accent: var(--primary-400);
            --accent-hover: var(--primary-300);
            --accent-soft: rgba(99, 102, 241, 0.1);
            --accent-light: rgba(99, 102, 241, 0.15);
            
            --success: var(--success-500);
            --success-light: rgba(34, 197, 94, 0.1);
            --warning: var(--warning-500);
            --warning-light: rgba(234, 179, 8, 0.1);
            --danger: var(--danger-500);
            --danger-light: rgba(239, 68, 68, 0.1);
            
            --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
            --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
            --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
            --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
            --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
        }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            padding: 0;
            min-height: 100vh;
            background: var(--surface);
            color: var(--text-primary);
            transition: background var(--transition-base), color var(--transition-base);
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        body[data-theme="dark"] {
            color-scheme: dark;
        }

        header {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 50;
            background: rgba(255, 255, 255, 0.85);
            border-bottom: 1px solid var(--border-subtle);
            backdrop-filter: blur(12px);
            box-shadow: var(--shadow-sm);
        }
        
        body[data-theme="dark"] header {
            background: rgba(30, 41, 59, 0.85);
        }

        .header-inner {
            max-width: 1200px;
            margin: 0 auto;
            padding: 1rem 1.5rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 1.5rem;
            flex-wrap: wrap;
        }

        .brand {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            text-decoration: none;
            color: var(--text-primary);
        }

        .logo-badge {
            width: 44px;
            height: 44px;
            border-radius: var(--radius-md);
            overflow: hidden;
            box-shadow: var(--shadow-md);
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .logo-badge img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .brand-text h1 {
            margin: 0;
            font-size: 1.125rem;
            font-weight: 700;
            letter-spacing: -0.01em;
        }

        .brand-text small {
            display: block;
            font-size: 0.75rem;
            color: var(--text-tertiary);
            margin-top: 2px;
        }

        .nav-links {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            flex: 1;
            justify-content: center;
        }

        .nav-links a {
            color: var(--text-secondary);
            text-decoration: none;
            font-weight: 500;
            font-size: 0.9375rem;
            padding: 0.5rem 1rem;
            border-radius: var(--radius-full);
            transition: all var(--transition-fast);
        }

        .nav-links a:hover {
            color: var(--text-primary);
            background: var(--accent-soft);
        }
        
        .nav-links a.active {
            color: var(--accent);
            background: var(--accent-soft);
            font-weight: 600;
        }

        .header-actions {
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        .session-actions {
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        #theme-toggle {
            background: var(--gray-100);
            border: none;
            color: var(--text-secondary);
            width: 40px;
            height: 40px;
            border-radius: var(--radius-md);
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 1.125rem;
            transition: all var(--transition-fast);
        }
        
        body[data-theme="dark"] #theme-toggle {
            background: rgba(148, 163, 184, 0.1);
            color: var(--text-primary);
        }

        #theme-toggle:hover {
            background: var(--gray-200);
            transform: scale(1.05);
        }
        
        body[data-theme="dark"] #theme-toggle:hover {
            background: rgba(148, 163, 184, 0.15);
        }

        main {
            max-width: 1200px;
            margin: 0 auto;
            padding: 7rem 1.5rem 4rem 1.5rem;
        }

        .card {
            background: var(--surface-elevated);
            border-radius: var(--radius-xl);
            box-shadow: var(--shadow-md);
            padding: 2rem;
            margin-bottom: 1.5rem;
            border: 1px solid var(--border-subtle);
            transition: all var(--transition-base);
        }

        .card:hover {
            box-shadow: var(--shadow-lg);
        }

        .card h2 {
            margin: 0 0 1rem 0;
            font-size: 1.875rem;
            font-weight: 700;
            letter-spacing: -0.02em;
            color: var(--text-primary);
        }

        .card h3 {
            margin: 0 0 0.75rem 0;
            font-size: 1.5rem;
            font-weight: 700;
            letter-spacing: -0.01em;
            color: var(--text-primary);
        }

        .card h4 {
            margin: 0 0 0.5rem 0;
            font-size: 1.125rem;
            font-weight: 600;
            color: var(--text-primary);
        }

        .button {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            padding: 0.625rem 1.25rem;
            border-radius: var(--radius-full);
            border: none;
            font-weight: 600;
            font-size: 0.9375rem;
            cursor: pointer;
            background: var(--accent);
            color: white;
            transition: all var(--transition-fast);
            text-decoration: none;
            box-shadow: var(--shadow-sm);
        }

        .button:hover {
            background: var(--accent-hover);
            transform: translateY(-1px);
            box-shadow: var(--shadow-md);
        }

        .button:active {
            transform: translateY(0);
        }

        .button.small {
            padding: 0.5rem 1rem;
            font-size: 0.875rem;
        }

        .button.secondary {
            background: var(--accent-soft);
            color: var(--accent);
            box-shadow: none;
        }

        .button.secondary:hover {
            background: var(--accent-light);
            box-shadow: none;
        }

        .button.link {
            background: none;
            color: var(--accent);
            box-shadow: none;
            padding: 0.5rem 0.75rem;
        }

        .button.link:hover {
            background: var(--accent-soft);
            box-shadow: none;
        }

        .button.danger {
            background: var(--danger);
            color: white;
        }

        .button.danger:hover {
            background: var(--danger-700);
        }

        .pill {
            display: inline-flex;
            align-items: center;
            gap: 0.375rem;
            border-radius: var(--radius-full);
            padding: 0.25rem 0.75rem;
            font-size: 0.8125rem;
            font-weight: 600;
            background: var(--accent-soft);
            color: var(--accent);
            letter-spacing: 0.01em;
        }
        
        .pill.success {
            background: var(--success-light);
            color: var(--success);
        }
        
        .pill.warning {
            background: var(--warning-light);
            color: var(--warning);
        }
        
        .pill.danger {
            background: var(--danger-light);
            color: var(--danger);
        }

        form label {
            display: block;
            font-weight: 600;
            font-size: 0.9375rem;
            margin-bottom: 0.5rem;
            margin-top: 1rem;
            color: var(--text-primary);
        }
        
        form label:first-of-type {
            margin-top: 0;
        }

        form input[type="text"],
        form input[type="email"],
        form input[type="password"],
        form input[type="date"],
        form select,
        form textarea {
            width: 100%;
            border-radius: var(--radius-md);
            padding: 0.75rem 1rem;
            border: 1px solid var(--border-medium);
            font-size: 0.9375rem;
            background: var(--surface-elevated);
            color: var(--text-primary);
            transition: all var(--transition-fast);
            font-family: inherit;
        }

        form textarea {
            resize: vertical;
            min-height: 100px;
        }

        form input:focus,
        form select:focus,
        form textarea:focus {
            outline: none;
            border-color: var(--accent);
            box-shadow: 0 0 0 3px var(--accent-soft);
        }

        form input::placeholder,
        form textarea::placeholder {
            color: var(--text-tertiary);
        }

        .inline-form {
            display: inline-block;
        }

        .action-group {
            display: flex;
            flex-wrap: wrap;
            gap: 0.75rem;
            align-items: center;
        }

        .toast {
            background: var(--accent-soft);
            border-left: 3px solid var(--accent);
            padding: 1rem 1.25rem;
            border-radius: var(--radius-md);
            font-size: 0.9375rem;
            color: var(--text-primary);
            line-height: 1.6;
        }

        .messages {
            margin-bottom: 1.5rem;
            display: grid;
            gap: 0.75rem;
        }

        .message {
            border-radius: var(--radius-md);
            padding: 0.875rem 1.125rem;
            border-left: 3px solid var(--accent);
            background: var(--accent-soft);
            color: var(--text-primary);
            font-weight: 500;
            font-size: 0.9375rem;
        }

        .message-success,
        .message.success {
            border-left-color: var(--success);
            background: var(--success-light);
        }

        .message-error,
        .message-danger,
        .message.error,
        .message.danger {
            border-left-color: var(--danger);
            background: var(--danger-light);
        }

        .message-info,
        .message.info {
            border-left-color: var(--accent);
            background: var(--accent-soft);
        }

        .message-warning,
        .message.warning {
            border-left-color: var(--warning);
            background: var(--warning-light);
        }

        .dashboard-grid {
            display: grid;
            gap: 1.25rem;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
        }

        .stat-card {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
            padding: 1.5rem;
            border-radius: var(--radius-lg);
            background: var(--surface-elevated);
            border: 1px solid var(--border-subtle);
            box-shadow: var(--shadow-sm);
            transition: all var(--transition-base);
        }

        .stat-card:hover {
            box-shadow: var(--shadow-md);
            transform: translateY(-2px);
        }

        .stat-value {
            font-size: 2.25rem;
            font-weight: 800;
            color: var(--text-primary);
            letter-spacing: -0.02em;
        }

        .stat-label {
            font-size: 0.875rem;
            font-weight: 500;
            color: var(--text-secondary);
        }

        .stat-description {
            font-size: 0.8125rem;
            color: var(--text-tertiary);
        }

        .meta-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 0.75rem;
        }

        .meta-item {
            display: flex;
            flex-direction: column;
            gap: 0.25rem;
            padding: 0.75rem;
            border-radius: var(--radius-md);
            background: var(--surface);
            border: 1px solid var(--border-subtle);
        }

        .meta-label {
            font-size: 0.8125rem;
            color: var(--text-tertiary);
            font-weight: 500;
        }

        .meta-value {
            font-size: 0.9375rem;
            color: var(--text-primary);
            font-weight: 600;
        }

        .section-heading {
            margin-top: 1.5rem;
            margin-bottom: 0.75rem;
            font-size: 1.125rem;
            font-weight: 700;
            color: var(--text-primary);
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .section-heading::before {
            content: "";
            width: 4px;
            height: 1.125rem;
            background: var(--accent);
            border-radius: var(--radius-full);
        }

        .hero-badge {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.5rem 1rem;
            background: var(--accent-soft);
            border: 1px solid var(--accent-light);
            border-radius: var(--radius-full);
            font-size: 0.875rem;
            font-weight: 600;
            color: var(--accent);
        }

        .progress-bar {
            position: relative;
            height: 8px;
            background: var(--gray-200);
            border-radius: var(--radius-full);
            overflow: hidden;
        }
        
        body[data-theme="dark"] .progress-bar {
            background: rgba(148, 163, 184, 0.1);
        }

        .progress-bar span {
            position: absolute;
            top: 0;
            left: 0;
            height: 100%;
            border-radius: inherit;
            background: linear-gradient(90deg, var(--accent), var(--primary-500));
            transition: width var(--transition-slow);
        }

        .mistake-feed,
        .feed {
            display: grid;
            gap: 1rem;
        }

        .feed-item {
            display: flex;
            flex-direction: column;
            gap: 0.75rem;
            background: var(--surface-elevated);
            border-radius: var(--radius-lg);
            padding: 1.25rem;
            border: 1px solid var(--border-subtle);
            transition: all var(--transition-base);
        }

        .feed-item:hover {
            box-shadow: var(--shadow-md);
            transform: translateY(-1px);
            border-color: var(--border-medium);
        }

        .feed-header {
            display: flex;
            justify-content: space-between;
            gap: 1rem;
            align-items: flex-start;
        }

        .feed-title {
            font-size: 1.0625rem;
            font-weight: 600;
            margin: 0;
            color: var(--text-primary);
            letter-spacing: -0.01em;
        }

        .feed-meta {
            display: flex;
            flex-wrap: wrap;
            gap: 0.75rem;
            font-size: 0.875rem;
            color: var(--text-secondary);
        }

        .feed-meta > span {
            display: flex;
            align-items: center;
            gap: 0.375rem;
        }

        .feed-status {
            padding: 0.3125rem 0.75rem;
            border-radius: var(--radius-full);
            font-size: 0.8125rem;
            font-weight: 600;
            letter-spacing: 0.01em;
            white-space: nowrap;
        }

        .feed-status.draft {
            background: var(--warning-light);
            color: var(--warning);
        }

        .feed-status.submitted {
            background: var(--accent-soft);
            color: var(--accent);
        }

        .feed-status.resolved {
            background: var(--success-light);
            color: var(--success);
        }

        @media (max-width: 768px) {
            .header-inner {
                padding: 0.875rem 1rem;
            }
            
            .brand-text small {
                display: none;
            }
            
            .nav-links {
                flex-basis: 100%;
                order: 3;
                justify-content: flex-start;
                padding-top: 0.5rem;
                border-top: 1px solid var(--border-subtle);
                gap: 0.25rem;
            }
            
            .nav-links a {
                padding: 0.5rem 0.75rem;
                font-size: 0.875rem;
            }
            
            .header-actions {
                flex-wrap: wrap;
            }
            
            .session-actions {
                gap: 0.5rem;
            }
            
            main {
                padding: 7.5rem 1rem 3rem 1rem;
            }
            
            .card {
                padding: 1.5rem;
            }
            
            .dashboard-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
    {% block extra_head %}{% endblock %}
</head>
<body data-theme="light">
    <header>
        <div class="header-inner">
            <a href="{% url 'learning:home' %}" class="brand">
                <div class="logo-badge">
                    <img src="/media/mistakes/logo.png" alt="高中数学助手Logo">
                </div>
                <div class="brand-text">
                    <h1>高中数学助手</h1>
                    <small>智能错题本管理平台</small>
                </div>
            </a>
            <nav class="nav-links">
                <a href="{% url 'learning:home' %}">首页</a>
                {% if user.is_authenticated %}
                    <a href="{% url 'learning:mistake_list' %}">错题本</a>
                    {% if user.is_student %}
                        <a href="{% url 'learning:topic_training_list' %}">专题训练</a>
                        <a href="{% url 'learning:notebook_list' %}">笔记本</a>
                    {% endif %}
                {% endif %}
                <a href="{% url 'learning:notebook_public' %}">公共笔记</a>
            </nav>
            <div class="header-actions">
                <div class="session-actions">
                    {% if user.is_authenticated %}
                        <a class="button small secondary" href="{% url 'accounts:profile' %}">
                            个人中心
                        </a>
                        <a class="button small link" href="{% url 'accounts:mailbox' %}" style="position:relative;">
                            信件
                            {% if notifications_unread_count %}
                                <span style="position:absolute;top:-4px;right:-6px;width:8px;height:8px;background:var(--danger);border-radius:50%;border:2px solid var(--surface-elevated);"></span>
                            {% endif %}
                        </a>
                        <a class="button small link" href="{% url 'accounts:logout' %}">退出</a>
                    {% else %}
                        <a class="button small secondary" href="{% url 'accounts:login' %}">登录</a>
                        <a class="button small" href="{% url 'accounts:register' %}">注册</a>
                    {% endif %}
                    <button id="theme-toggle" type="button" aria-label="切换主题">🌙</button>
                </div>
            </div>
        </div>
    </header>
    <main>
        {% if messages %}
            <div class="messages">
                {% for message in messages %}
                    <div class="message message-{{ message.tags }}">{{ message }}</div>
                {% endfor %}
            </div>
        {% endif %}
        {% block content %}{% endblock %}
    </main>
    <script>
        (function () {
            const root = document.body;
            const toggle = document.getElementById("theme-toggle");
            if (!toggle) return;

            const saved = localStorage.getItem("mathassist-theme");
            if (saved) {
                root.dataset.theme = saved;
                toggle.textContent = saved === "dark" ? "☀️" : "🌙";
            }

            toggle.addEventListener("click", () => {
                const nextTheme = root.dataset.theme === "dark" ? "light" : "dark";
                root.dataset.theme = nextTheme;
                localStorage.setItem("mathassist-theme", nextTheme);
                toggle.textContent = nextTheme === "dark" ? "☀️" : "🌙";
            });
        })();
    </script>
</body>
</html>
